package com.hzp.net.netty.server.handler.http;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

public class NettyHttpFactory {

    private static NettyHttpFactory instance = null;

    private TemplateEngine templateEngine;

    private NettyHttpFactory() {
        ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
        resolver.setTemplateMode("XHTML");
        resolver.setPrefix("/WEB-INF/templates/http/");
        resolver.setSuffix(".html");
        templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(resolver);
    }

    public static NettyHttpFactory getInstance() {
        if (instance == null){
            instance = new NettyHttpFactory();
        }
        return instance;
    }

    public String process(String name){
        return templateEngine.process(name,new Context());
    }
}
